/*

This file is part of Sencha Touch 2

Copyright (c) 2012 Sencha Inc

Contact:  http://www.sencha.com/contact

Commercial Usage
Licensees holding valid commercial licenses may use this file in accordance with the Commercial Software License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and Sencha.

If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.

*/
//(function(global){var emptyFn=function(){},callbacks=[],doc=global.document,head=doc.head,addWindowListener=global.addEventListener,storage=global.localStorage,appCache=global.applicationCache,jsonParse=JSON.parse,a=doc.createElement("a"),documentLocation=doc.location,documentUri=documentLocation.origin+documentLocation.pathname+documentLocation.search,manifestFile="app.json",isRefreshing=false,activeManifest;function getManifestStorageKey(id){return id+"-"+documentUri+manifestFile}function Manifest(manifest){var manifestContent;if(typeof manifest=="string"){manifestContent=manifest;manifest=jsonParse(manifestContent)}else{manifestContent=JSON.stringify(manifest)}var applicationId=manifest.id,key=getManifestStorageKey(applicationId),assetMap={};function processAsset(asset){var uri;if(typeof asset=="string"){asset={path:asset}}if(asset.shared){asset.version=asset.shared;uri=asset.shared+asset.path}else{uri=toAbsoluteUri(asset.path)}asset.uri=uri;asset.key=applicationId+"-"+uri;assetMap[uri]=asset;return asset}function processAssets(assets,type){var ln=assets.length,i,asset;for(i=0;i<ln;i++){asset=assets[i];assets[i]=asset=processAsset(asset);asset.type=type;asset.index=i;asset.collection=assets;asset.ready=false;asset.evaluated=false}return assets}this.key=key;this.css=processAssets(manifest.css,"css");this.js=processAssets(manifest.js,"js");this.assets=this.css.concat(this.js);this.getAsset=function(uri){return assetMap[uri]};this.store=function(){store(key,manifestContent)}}if(typeof Ext==="undefined"){var Ext=global.Ext={}}function toAbsoluteUri(uri){a.href=uri;return a.href}function writeMeta(name,content){doc.write('<meta name="'+name+'" content="'+content+'">')}function request(uri,isShared,onSuccess,onFailure){(isShared?requestIframe:requestXhr)(uri,onSuccess,onFailure)}function requestXhr(uri,onSuccess,onFailure){var xhr=new XMLHttpRequest(),status;onFailure=onFailure||emptyFn;try{xhr.open("GET",uri,true);xhr.onreadystatechange=function(){if(xhr.readyState==4){status=xhr.status;if(status==200||status==304||status==0){onSuccess(xhr.responseText)}else{onFailure()}}};xhr.send(null)}catch(e){onFailure()}}function requestIframe(uri,onSuccess){var iframe=doc.createElement("iframe");callbacks.push({iframe:iframe,callback:onSuccess});iframe.src=uri+".html";iframe.style.cssText="width:0;height:0;border:0;position:absolute;z-index:-999;visibility:hidden";doc.body.appendChild(iframe)}function requestAsset(asset,onSuccess,onFailure){var isShared=!!asset.shared;if(!isShared){var onRequestSuccess=onSuccess,version=asset.version,remoteChecksumBlock;onSuccess=function(content){remoteChecksumBlock=content.substring(0,version.length+4);if(remoteChecksumBlock!=="/*"+version+"*/"){if(confirm("Requested: '"+asset.uri+"' with checksum: "+version+" but received: "+remoteChecksumBlock.substring(2,version.length)+"instead. Attemp to refresh the application?")){refresh()}return}onRequestSuccess(content)}}request(asset.uri,isShared,onSuccess,onFailure)}function onMessage(e){var data=e.data,sourceWindow=e.source.window,i,ln,callback,iframe;for(i=0,ln=callbacks.length;i<ln;i++){callback=callbacks[i];iframe=callback.iframe;if(iframe.contentWindow===sourceWindow){callback.callback(data);doc.body.removeChild(iframe);callbacks.splice(i,1);return}}}function patch(content,delta){var output=[],chunk,i,ln;if(delta.length===0){return content}for(i=0,ln=delta.length;i<ln;i++){chunk=delta[i];if(typeof chunk==="number"){output.push(content.substring(chunk,chunk+delta[++i]))}else{output.push(chunk)}}return output.join("")}function log(message){if(typeof console!="undefined"){(console.error||console.log).call(console,message)}}function store(key,value){try{storage.setItem(key,value)}catch(e){if(e.code==e.QUOTA_EXCEEDED_ERR){var items=activeManifest.assets.map(function(asset){return asset.key}),i=0,ln=storage.length,cleaned=false,item;items.push(activeManifest.key);while(i<=ln-1){item=storage.key(i);if(items.indexOf(item)==-1){storage.removeItem(item);cleaned=true;ln--}else{i++}}if(cleaned){store(key,value)}}}}function retrieve(key){try{return storage.getItem(key)}catch(e){return null}}function retrieveAsset(asset){return retrieve(asset.key)}function storeAsset(asset,content){return store(asset.key,content)}function refresh(){if(!isRefreshing){isRefreshing=true;requestXhr(manifestFile,function(content){new Manifest(content).store();global.location.reload()})}}function blink(currentManifest){var currentAssets=currentManifest.assets,assetsCount=currentAssets.length,newManifest;activeManifest=currentManifest;addWindowListener("message",onMessage,false);function onAssetReady(asset,content){var assets=asset.collection,index=asset.index,ln=assets.length,i;asset.ready=true;asset.content=content;for(i=index-1;i>=0;i--){asset=assets[i];if(!asset.ready||!asset.evaluated){return}}for(i=index;i<ln;i++){asset=assets[i];if(asset.ready){if(!asset.evaluated){evaluateAsset(asset)}}else{return}}}function evaluateAsset(asset){asset.evaluated=true;if(asset.type=="js"){try{eval(asset.content)}catch(e){log("Error evaluating "+asset.uri+" with message: "+e)}}else{var style=doc.createElement("style"),base;style.type="text/css";style.textContent=asset.content;if("id" in asset){style.id=asset.id}if("disabled" in asset){style.disabled=asset.disabled}base=document.createElement("base");base.href=asset.path.replace(/\/[^\/]*$/,"/");head.appendChild(base);head.appendChild(style);head.removeChild(base)}delete asset.content;if(--assetsCount==0){onReady()}}function onReady(){var updatingAssets=[],appCacheReady=false,appCacheIdle=false,onAppCacheIdle=function(){appCacheIdle=true},onAppCacheReady=function(){appCache.swapCache();appCacheReady=true;onAppCacheIdle()},updatingCount;global.removeEventListener("message",onMessage,false);if(appCache.status==appCache.UPDATEREADY){onAppCacheReady()}else{if(appCache.status==appCache.CHECKING||appCache.status==appCache.DOWNLOADING){appCache.onupdateready=onAppCacheReady;appCache.onnoupdate=appCache.onobsolete=onAppCacheIdle}else{onAppCacheIdle()}}function notifyUpdateIfAppCacheReady(){if(appCacheReady){notifyUpdate()}}function notifyUpdate(){var updatedCallback=Ext.onUpdated||emptyFn;if("onSetup" in Ext){Ext.onSetup(updatedCallback)}else{updatedCallback()}}function doUpdate(){newManifest.store();updatingAssets.forEach(function(asset){storeAsset(asset,asset.content)});notifyUpdate()}function onAssetUpdated(asset,content){asset.content=content;if(--updatingCount==0){if(appCacheIdle){doUpdate()}else{onAppCacheIdle=doUpdate}}}if(navigator.onLine!==false){requestXhr(manifestFile,function(manifestContent){activeManifest=newManifest=new Manifest(manifestContent);var assets=newManifest.assets,currentAsset;assets.forEach(function(asset){currentAsset=currentManifest.getAsset(asset.uri);if(!currentAsset||asset.version!==currentAsset.version){updatingAssets.push(asset)}});updatingCount=updatingAssets.length;if(updatingCount==0){if(appCacheIdle){notifyUpdateIfAppCacheReady()}else{onAppCacheIdle=notifyUpdateIfAppCacheReady}return}updatingAssets.forEach(function(asset){var currentAsset=currentManifest.getAsset(asset.uri),path=asset.path,update=asset.update;function updateFull(){requestAsset(asset,function(content){onAssetUpdated(asset,content)})}if(!currentAsset||!update||retrieveAsset(asset)===null||update!="delta"){updateFull()}else{requestXhr("deltas/"+path+"/"+currentAsset.version+".json",function(content){try{onAssetUpdated(asset,patch(retrieveAsset(asset),jsonParse(content)))}catch(e){log("Malformed delta content received for "+asset.uri)}},updateFull)}})})}}if(assetsCount==0){onReady();return}currentAssets.forEach(function(asset){var content=retrieveAsset(asset);if(content===null){requestAsset(asset,function(content){storeAsset(asset,content);onAssetReady(asset,content)},function(){onAssetReady(asset,"")})}else{onAssetReady(asset,content)}})}function blinkOnDomReady(manifest){if(doc.readyState.match(/interactive|complete|loaded/)!==null){blink(manifest)}else{addWindowListener("DOMContentLoaded",function(){blink(manifest)},false)}}Ext.blink=function(manifest){var manifestContent=retrieve(getManifestStorageKey(manifest.id));writeMeta("viewport","width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no");writeMeta("apple-mobile-web-app-capable","yes");writeMeta("apple-touch-fullscreen","yes");if(manifestContent){manifest=new Manifest(manifestContent);blinkOnDomReady(manifest)}else{requestXhr(manifestFile,function(content){manifest=new Manifest(content);manifest.store();blinkOnDomReady(manifest)})}}})(this);
//Error->Browser can't refresh the application
(function (n) {
    function r(a) {
        function b(a, j) { var c = a.length, b, e; for (b = 0; b < c; b++) { e = a[b]; var d = a, J = b, k = void 0; "string" == typeof e && (e = { path: e }); e.shared ? (e.version = e.shared, k = e.shared + e.path) : (y.href = e.path, k = y.href); e.uri = k; e.key = g + "-" + k; f[k] = e; d[J] = e; e.type = j; e.index = b; e.collection = a; e.ready = !1; e.evaluated = !1 } return a } var c; "string" == typeof a ? (c = a, a = z(c)) : c = JSON.stringify(a); var g = a.id, d = g + "-" + A + o, f = {}; this.key = d; this.css = b(a.css, "css"); this.js = b(a.js, "js"); this.assets = this.css.concat(this.js); this.getAsset =
function (a) { return f[a] }; this.store = function () { s(d, c) } 
    } function v(a, b) { i.write('<meta name="' + a + '" content="' + b + '">') } function p(a, b, c) { var g = new XMLHttpRequest, d, c = c || B, a = a + (-1 == a.indexOf("?") ? "?" : "&") + Date.now(); try { g.open("GET", a, !0), g.onreadystatechange = function () { 4 == g.readyState && (d = g.status, 200 == d || 304 == d || 0 == d ? b(g.responseText) : c()) }, g.send(null) } catch (f) { c() } } function K(a, b) {
        var c = i.createElement("iframe"); m.push({ iframe: c, callback: b }); c.src = a + ".html"; c.style.cssText = "width:0;height:0;border:0;position:absolute;z-index:-999;visibility:hidden";
        i.body.appendChild(c)
    } function C(a, b, c) { var g = !!a.shared; if (!g) var d = b, f = a.version, h, b = function (j) { h = j.substring(0, f.length + 4); h !== "/*" + f + "*/" ? confirm("Requested: '" + a.uri + "' with checksum: " + f + " but received: " + h.substring(2, f.length) + "instead. Attempt to refresh the application?") && L() : d(j) }; (g ? K : p)(a.uri, b, c) } function D(a) { var b = a.data, a = a.source.window, c, g, d, f; for (c = 0, g = m.length; c < g; c++) if (d = m[c], f = d.iframe, f.contentWindow === a) { d.callback(b); i.body.removeChild(f); m.splice(c, 1); break } } function E(a) {
        "undefined" !=
typeof console && (console.error || console.log).call(console, a)
    } function s(a, b) { try { l.setItem(a, b) } catch (c) { if (c.code == c.QUOTA_EXCEEDED_ERR) { var g = t.assets.map(function (a) { return a.key }), d = 0, f = l.length, h = !1, j; for (g.push(t.key); d <= f - 1; ) j = l.key(d), -1 == g.indexOf(j) ? (l.removeItem(j), h = !0, f--) : d++; h && s(a, b) } } } function u(a) { try { return l.getItem(a) } catch (b) { return null } } function L() { F || (F = !0, p(o, function (a) { (new r(a)).store(); n.location.reload() })) } function G(a) {
        function b(a, b) {
            var d = a.collection, e = a.index,
g = d.length, f; a.ready = !0; a.content = b; for (f = e - 1; 0 <= f; f--) if (a = d[f], !a.ready || !a.evaluated) return; for (f = e; f < g; f++) if (a = d[f], a.ready) a.evaluated || c(a); else break
        } function c(a) {
            a.evaluated = !0; if ("js" == a.type) try { eval(a.content) } catch (b) { E("Error evaluating " + a.uri + " with message: " + b) } else {
                var c = i.createElement("style"), e; c.type = "text/css"; c.textContent = a.content; "id" in a && (c.id = a.id); "disabled" in a && (c.disabled = a.disabled); e = document.createElement("base"); e.href = a.path.replace(/\/[^\/]*$/, "/"); w.appendChild(e);
                w.appendChild(c); w.removeChild(e)
            } delete a.content; 0 == --f && g()
        } function g() {
            function c() { d && b() } function b() { var a = q.onUpdated || B; if ("onSetup" in q) q.onSetup(a); else a() } function f() { l.store(); e.forEach(function (a) { s(a.key, a.content) }); b() } var e = [], d = !1, g = !1, k = function () { g = !0 }, i = function () { h.swapCache(); d = !0; k() }, m; n.removeEventListener("message", D, !1); h.status == h.UPDATEREADY ? i() : h.status == h.CHECKING || h.status == h.DOWNLOADING ? (h.onupdateready = i, h.onnoupdate = h.onobsolete = function () { k() }) : k(); !1 !== navigator.onLine &&
p(o, function (b) {
    t = l = new r(b); var d; l.assets.forEach(function (b) { d = a.getAsset(b.uri); (!d || b.version !== d.version) && e.push(b) }); m = e.length; 0 == m ? g ? c() : k = c : e.forEach(function (b) {
        function c() { C(b, function (a) { b.content = a; 0 == --m && (g ? f() : k = f) }) } var d = a.getAsset(b.uri), e = b.path, h = b.update; !d || !h || null === u(b.key) || "delta" != h ? c() : p("deltas/" + e + "/" + d.version + ".json", function (a) {
            try {
                var c = b, d; var e = u(b.key), h = z(a), a = [], j, i, l; if (0 === h.length) d = e; else {
                    for (i = 0, l = h.length; i < l; i++) j = h[i], "number" === typeof j ? a.push(e.substring(j,
j + h[++i])) : a.push(j); d = a.join("")
                } c.content = d; 0 == --m && (g ? f() : k = f)
            } catch (n) { E("Malformed delta content received for " + b.uri) } 
        }, c)
    })
})
        } var d = a.assets, f = d.length, l; t = a; H("message", D, !1); 0 == f ? g() : d.forEach(function (a) { var c = u(a.key); null === c ? C(a, function (c) { s(a.key, c); b(a, c) }, function () { b(a, "") }) : b(a, c) })
    } function I(a) { null !== i.readyState.match(/interactive|complete|loaded/) ? G(a) : H("DOMContentLoaded", function () { G(a) }, !1) } var B = function () { }, m = [], i = n.document, w = i.head, H = n.addEventListener, l = n.localStorage,
h = n.applicationCache, z = JSON.parse, y = i.createElement("a"), x = i.location, A = x.origin + x.pathname + x.search, o = "app.json", F = !1, t; if ("undefined" === typeof q) var q = n.Ext = {}; q.blink = function (a) { var b = u(a.id + "-" + A + o); v("viewport", "width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"); v("apple-mobile-web-app-capable", "yes"); v("apple-touch-fullscreen", "yes"); b ? (a = new r(b), I(a)) : p(o, function (b) { a = new r(b); a.store(); I(a) }) } 
})(this);
